package com.work.formaldehyde.activityadapter;

import android.app.Activity;
import android.content.Context;
import android.content.DialogInterface;
import android.os.Handler;
import android.text.Editable;
import android.text.TextUtils;
import android.text.TextWatcher;
import android.text.format.Time;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.BaseAdapter;
import android.widget.EdgeEffect;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.PopupWindow;
import android.widget.RelativeLayout;
import android.widget.TextView;

import androidx.appcompat.app.AlertDialog;
import androidx.recyclerview.widget.RecyclerView;

import com.bigkoo.pickerview.builder.TimePickerBuilder;
import com.bigkoo.pickerview.listener.OnTimeSelectListener;
import com.bigkoo.pickerview.view.TimePickerView;
import com.work.formaldehyde.R;
import com.work.formaldehyde.activity.GouWuCheJieSuanActivity;
import com.work.formaldehyde.model.AllDingDanModel;
import com.work.formaldehyde.model.GouWuCheModel;
import com.work.formaldehyde.model.StringModel;
import com.work.formaldehyde.util.ApiUtils;

import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;

public class GouWuCheJieSuanAdapter extends BaseAdapter {
    ArrayList<GouWuCheModel.data> list;
    Context context;
    ArrayList<String> list1;
    Activity acti;
    ArrayList<String> list2;
    int xianshi;
    ArrayList<AllDingDanModel.data> new_list_views1s;

    public GouWuCheJieSuanAdapter(ArrayList<GouWuCheModel.data> list, ArrayList<AllDingDanModel.data> new_list_views1s, Context context, ArrayList<String> list1, Activity acti,
                                  ArrayList<String> list2, int xianshi) {
        // TODO Auto-generated constructor stub
        this.list = list;
        this.list1 = list1;
        this.context = context;
        this.acti = acti;
        this.list2 = list2;
        this.xianshi = xianshi;
        this.new_list_views1s = new_list_views1s;
    }

    @Override
    public int getCount() {
        // TODO Auto-generated method stub
        return list != null ? list.size() : 0;
    }

    @Override
    public Object getItem(int position) {
        // TODO Auto-generated method stub
        return list != null ? list.get(position) : 0;
    }

    @Override
    public long getItemId(int position) {
        // TODO Auto-generated method stub
        return position;
    }

    public init i;

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        // TODO Auto-generated method stub
        convertView = LayoutInflater.from(context).inflate(R.layout.activity_querendingdangouwuche, null);
        i = new init();
        i.gouwuche_img = convertView.findViewById(R.id.gouwuche_img);
        i.gouwuche_name = convertView.findViewById(R.id.shangpingmingzi);
        i.gouwuche_money = convertView.findViewById(R.id.gouwuche_money);
        i.gouwuche_numtext = convertView.findViewById(R.id.gouwuche_numtext);
        i.xianshi = convertView.findViewById(R.id.xianshi);
        if(xianshi==0) {
            i.gouwuche_name.setText(list.get(position).getGoods_name());
            ApiUtils.GET_IMAGE(context, list.get(position).getGoods_img(), i.gouwuche_img);
            double money = Double.parseDouble(list.get(position).getGoods_discount_price());
            double moneynum = Double.parseDouble(list.get(position).getGoods_num());
            double moneyall = money * moneynum;
            String allmoneys = new DecimalFormat("0.00").format(moneyall);
            i.gouwuche_money.setText("¥" + allmoneys);
            i.gouwuche_numtext.setText("x" + list.get(position).getGoods_num());
        }else{
            i.gouwuche_name.setText(new_list_views1s.get(0).getGoods().get(position).getGoods_name());
            ApiUtils.GET_IMAGE(context, new_list_views1s.get(0).getGoods().get(position).getGoods_img(), i.gouwuche_img);
            double money = Double.parseDouble(new_list_views1s.get(0).getGoods().get(position).getGoods_discount_price());
            double moneynum = Double.parseDouble(new_list_views1s.get(0).getGoods().get(position).getGoods_num());
            double moneyall = money * moneynum;
            String allmoneys = new DecimalFormat("0.00").format(moneyall);
            i.gouwuche_money.setText("¥" + allmoneys);
            i.gouwuche_numtext.setText("x" + new_list_views1s.get(0).getGoods().get(position).getGoods_num());
        }
        convertView.setTag(i);
        return convertView;
    }


    public static class init {
        //首页list的子控件
        LinearLayout xianshi;
        ImageView gouwuche_img;
        TextView  gouwuche_name, gouwuche_money, gouwuche_numtext;
    }


}

